<?php

 
 class Controller_News extends Controller_Base_Admin {
 	 	
 	function index($args) {
		$template = new Template('admin/index.tmpl');
		
		$news = new Model_News();
		
		if($_POST[action] === 'add') {
			$news->add('');
		}
		
		if($_GET[action] === 'delete') {
			$news->delete($_GET[id]);
		}
		
		$template->setArgs(
			array(
				'menu'		 	=> $this->menu->getHierarchicalMenu(array(uid => $this->admin->id)),
				'tabs'			=> $this->tabs->get('news'),
				'news'			=> $news->find(array(limit => 5)),
				'_user'			=> $this->admin
			)
		);

		return array (
			status		=> 0,
			template	=> $template
		);		
 	}
 	
 	function news_edit($args) {
		$template = new Template('admin/index.tmpl'); 		

		$news = new Model_News();

		$id = $_GET[id];
		
		if(isset($_POST[id])) {
			$news->save($_POST);
			$id = $_POST[id];
		}
//print_r($news->find(array(id => $id)));
		$template->setArgs(
			array(
				'menu'		 	=> $this->menu->getHierarchicalMenu(array(uid => $this->admin->id)),
				'tabs'			=> $this->tabs->get('news_edit'),
				'news'			=> $news->find(array(id => $id)),
				'_user'			=> $this->admin
			)
		);

		return array (
			status		=> 0,
			template	=> $template
		);		

 	}
 	
 }